<?php
namespace app\index\controller;

use think\Controller;
use think\View;
use Jssdk\JSSDK;
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2017/8/1
 * Time: 11:16
 */
class Activity extends CheckMember {

    /**
     * 活动列表
     * @return \think\response\View
     */
    public function index(){
        return view();
    }

    // 获取活动列表
    public function get_activity_list() {
        $param = input('param.');
        $param['member_id'] = session('member_id');
        $data = local_invoke_api('get_activity_list', $param);
        $view = new View();
        $view->assign('data', $data['data']);
        $tpl = $view->fetch('activity_list_tpl');
        $data['tpl'] = $tpl;
        //dump($data);
        return json($data);
    }


    /**
     * 活动详情
     * @return \think\response\View
     */
    public function info(){
        $param['id'] = input('param.id');
        $param['member_id'] = session('member_id');
        $data = $this->local_invoke_api('get_activity_info', $param);
//        dump($data);
        if (request()->isAjax()) {
            if (input('param.type', '') == 'nearby') {
                $view = new View();
                $view->assign('data', $data['data']);
                $tpl = $view->fetch('friend/activity_info_tpl');
                $data['tpl'] = $tpl;
            }
            return json($data);
        } else {
            $this->assign('data', $data['data']);
            return view();
        }
    }

    /**
     * 参加活动
     * @return \think\response\Json
     */
    public function participate() {
        $param['id'] = input('param.id');
        $param['member_id'] = session('member_id');
        $data = $this->local_invoke_api('participate_activity', $param);
        return json($data);
    }

    /**
     * 退出活动
     * @return \think\response\Json
     */
    public function quit_activity() {
        $param['id'] = input('param.id');
        $param['member_id'] = session('member_id');
        $data = $this->local_invoke_api('quit_activity', $param);
        return json($data);
    }

    /**
     * 活动用户
     * @return \think\response\View
     */
    public function activity_member() {
        if (request()->isAjax()) {
            $param= input('param.');
            $param['member_id'] = session('member_id');
            $data = $this->local_invoke_api('get_activity_member', $param);

            $view = new View();
            $view->assign('data', $data['data']);
            $tpl = $view->fetch('activity_member_tpl');
            $data['tpl'] = $tpl;
            return json($data);
        } else {
            $this->assign('id', input('param.id'));
            return view();
        }
    }

    /**
     * 审核获取申请用户
     * @return \think\response\Json
     */
    public function edit_member_status() {
        $param= input('param.');
        $param['member_id'] = session('member_id');
        $data = $this->local_invoke_api('edit_member_status', $param);
        return json($data);
    }


    /**
     * 活动群组聊天页面
     * @return \think\response\View
     */
    public function group_chat() {
        // 获取融云信息
        $param['member_id'] = session('member_id');
        $data = $this->local_invoke_api('get_member_rong_info', $param);
        $this->assign('data', $data['data']);

        $param['id'] = input('param.id');
        $group = $this->local_invoke_api('get_group_chat_info', $param);
        $this->assign('group', $group['data']);

//        // 获取群聊天记录
//        $list = $this->local_invoke_api('get_group_chat_data_by_group_id', ['group_id' => $group['data']['group_id'], 'member_id' => session('member_id')]);
//        //dump($list);exit;
//        $this->assign('list', $list['data']);

        $this->assign('id', input('param.id'));
        return view('create_chat');
    }

    /**
     * 获取群组成员信息
     * @return \think\response\Json
     */
    public function get_activity_group_member() {
        $param= input('param.');
        $param['member_id'] = session('member_id');
        $data = $this->local_invoke_api('get_activity_group_member', $param);
        return json($data);
    }

    /**
     * 活动签到
     * @return \think\response\Json
     */
    public function activity_registration() {
        $param = input('param.');
        $param['member_id'] = session('member_id');
        $data = local_invoke_api('activity_registration', $param);
        return json($data);
    }
}